package com.xuhai.blog19.api;

import com.xuhai.blog19.admin.service.ArticleService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/2/10/010
 */
@RestController
@RequestMapping("/api/article")
public class ApiArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/hot/{page}")
    public R hot(@PathVariable Integer page) {
        return R.ok().data(articleService.getHotPage(page));
    }

    @GetMapping("/category/{categoryId}/{page}")
    public R pageByCategoryId(@PathVariable Integer categoryId, @PathVariable Integer page) {
        return R.ok().data(articleService.getArticlePageByCategoryId(page, categoryId));
    }

    @GetMapping("/info/{articleId}")
    public R info(@PathVariable Integer articleId) {
        return R.ok().data(articleService.getById(articleId));
    }

    @PostMapping("/{articleId}/read")
    public R updateReadCount(@PathVariable Integer articleId) {
        articleService.updateReadCount(articleId);
        return R.ok();
    }
}
